package com.ruoyi.project.system.student.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.student.domain.ClassStudent;
import com.ruoyi.project.system.student.service.IClassStudentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 班级-学生关联Controller
 * 
 * @author ruoyi
 * @date 2021-04-15
 */
@Controller
@RequestMapping("/system/student")
public class ClassStudentController extends BaseController
{
    private String prefix = "system/student";

    @Autowired
    private IClassStudentService classStudentService;

    @RequiresPermissions("system:student:view")
    @GetMapping()
    public String student()
    {
        return prefix + "/student";
    }

    /**
     * 查询班级-学生关联列表
     */
    @RequiresPermissions("system:student:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClassStudent classStudent)
    {
        startPage();
        List<ClassStudent> list = classStudentService.selectClassStudentList(classStudent);
        return getDataTable(list);
    }

    /**
     * 导出班级-学生关联列表
     */
    @RequiresPermissions("system:student:export")
    @Log(title = "班级-学生关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClassStudent classStudent)
    {
        List<ClassStudent> list = classStudentService.selectClassStudentList(classStudent);
        ExcelUtil<ClassStudent> util = new ExcelUtil<ClassStudent>(ClassStudent.class);
        return util.exportExcel(list, "student");
    }

    /**
     * 新增班级-学生关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存班级-学生关联
     */
    @RequiresPermissions("system:student:add")
    @Log(title = "班级-学生关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClassStudent classStudent)
    {
        return toAjax(classStudentService.insertClassStudent(classStudent));
    }

    /**
     * 修改班级-学生关联
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ClassStudent classStudent = classStudentService.selectClassStudentById(id);
        mmap.put("classStudent", classStudent);
        return prefix + "/edit";
    }

    /**
     * 修改保存班级-学生关联
     */
    @RequiresPermissions("system:student:edit")
    @Log(title = "班级-学生关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClassStudent classStudent)
    {
        return toAjax(classStudentService.updateClassStudent(classStudent));
    }

    /**
     * 删除班级-学生关联
     */
    @RequiresPermissions("system:student:remove")
    @Log(title = "班级-学生关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(classStudentService.deleteClassStudentByIds(ids));
    }
}
